Xceed Toolkit Plus for WPF v4.6 Documentation
Drag-and-Drop Operations
Welcome to Xceed Toolkit Plus for WPF v4.6 > DataGrid, ListBox, Chart, AvalonDock, and PropertyGrid > Listbox control > Drag-and-Drop Operations

The ListBox class and the classes contained in the Xceed.Wpf.DragDrop namespace provide support for flexible drag-and-drop operations, through events that determine whether a drop operation can occur (IDropTargetCanDropElement) with an IDropTarget-derived control, as well as events related to entering (IDropTargetDragEnter), leaving (IDropTargetDragLeave), dragging over (IDropTargetDragOver), and dropping on (IDropTargetDrop) an IDropTarget-derived control.

To enable drag operations from the listbox, the AllowDrag property must be set to true.

You must implement the IDropTarget interface on a control you wish to be able to accept the dragged elements.

The appearance and behavior of items dragged from the listbox can be configured by setting the DraggedElementConfiguration property of the ContainerConfigurations instance accessible via the listbox's ContainerConfigurations property.

<xclb:ListBox x:Name="productsListBox"

              AllowDrag="True"

              Margin="5"

              Grid.Column="0"

              Grid.Row="1"

              ItemsSource="{Binding Products}"

              ToolPaneVisibility="Collapsed"

              ItemTemplate="{StaticResource productListBoxItemTemplate}"

              SelectionMode="Extended"

              DragStarting="ProductsListBox_DragStarting">



...



    <xclb:ContainerConfigurations>

      <xclb:ContainerConfigurations.DraggedElementConfiguration>

         <xclb:DraggedElementConfiguration PositionAdornerRelativeToElement="False"

                                        DisplaySiblingElements="False"

                                        ElementTemplate="{StaticResource productDraggedElementTemplate}"

                                        CanDropCursor="Custom"

                                        CanDropCursorTemplate="{StaticResource addToCartCursorTemplate}"

                                        NoDropCursor="Custom"

                                        NoDropCursorTemplate="{StaticResource noDropCursorTemplate}" />

      </xclb:ContainerConfigurations.DraggedElementConfiguration>

    </xclb:ContainerConfigurations>

  </xclb:ListBox.ContainerConfigurations>

</xclb:ListBox>

Pre-defined cursors for CanDropCursor and NoDropCursor are available in the DragDropCursor enumeration. CanDropCursor is shown when a drop operation can be performed. When this property is set to DragDropCursor.Custom, the data template in CanDropCursorTemplate is used instead. The NoDropCursor is shown when a drop operation cannot be performed. When this property is set to DragDropCursor.Custom, the data template in NoDropCursorTemplate is used instead.

The DisplaySiblingElements property determines whether dragged sibling elements will be displayed during the operation, while the SiblingElementTemplate provides the data template for those elements.

The PositionAdornerRelativeToElement property determines whether the dragged element is positioned underneath the adorner (the cursor).

Finally, how quickly dragged/dropped elements fade in and out is determined by the ElementFadeInDuration and the ElementFadeOutDuration properties, respectively.

The ListBoxContainer-derived classes (ListBoxItem and ListBoxGroupHeader) implement the IProvideDraggedContentPresenter interface. By implementing this interface in your own controls, you can create controls that present content as these listbox elements do during drag operations.